dnl
dnl configure.in helper macros
dnl

AC_DEFUN([WITH_MYSQL], [
  	if test "x$PORTNAME" = "x"
  	then 
		EXTENSAO=""
	else
		EXTENSAO=".exe"
	fi
  AC_MSG_CHECKING(for mysql_config executable)

  AC_ARG_WITH(mysql, [  --with-mysql=PATH path to mysql_config binary or mysql prefix dir], [
  if test -x $withval -a -f $withval
    then
      MYSQL_CONFIG=$withval
    elif test -x $withval/bin/mysql_config$EXTENSAO -a -f $withval/bin/mysql_config$EXTENSAO
    then
     MYSQL_CONFIG=$withval/bin/mysql_config$EXTENSAO
    fi
  ], [
  if test -x /usr/local/mysql/bin/mysql_config$EXTENSAO -a -f /usr/local/mysql/bin/mysql_config$EXTENSAO
    then
      MYSQL_CONFIG=/usr/local/mysql/bin/mysql_config$EXTENSAO
    elif test -x /usr/bin/mysql_config$EXTENSAO -a -f /usr/bin/mysql_config$EXTENSAO
    then
      MYSQL_CONFIG=/usr/bin/mysql_config$EXTENSAO
    fi
  ])

  if test "x$MYSQL_CONFIG" = "x"
  then
    AC_MSG_RESULT(not found)
    exit 3
  else
    AC_MSG_RESULT($MYSQL_CONFIG)
    AC_PROG_CC
    AC_PROG_CXX

    # add regular MySQL C flags
    ADDFLAGS="$ADDFLAGS "`$MYSQL_CONFIG --cflags`

    # add NDB API specific C flags
    IBASE=`$MYSQL_CONFIG --include`
    ADDFLAGS="$ADDFLAGS $IBASE"

    CFLAGS="$CFLAGS $ADDFLAGS "
    CXXFLAGS="$CXXFLAGS $ADDFLAGS "

    LDFLAGS="$LDFLAGS "`$MYSQL_CONFIG --libs`" "
    
  fi
])